package com.example.proxy.Impi;

import com.example.proxy.AccessData;

public class ProxyImpi implements AccessData {
    private UserImpi userImpi;
    private String username;

    public ProxyImpi(String username) {
        this.username = username;
    }

    /**
     * 代理模式下，代码不一定会全部执行完，因为会存在判断逻辑
     */
    @Override
    public void access() {
        if (username.equalsIgnoreCase("admin")) {
            if (userImpi == null) {
                userImpi = new UserImpi();
            }
            userImpi.access();
        } else {
            System.out.println("访问失败");
        }
    }
}
